package com.zhzh.sc.demo.leetcode.easy;

import java.util.Arrays;


/**

 ### [1480\. Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/)

 Difficulty: **Easy**

 Related Topics: [Array](https://leetcode.com/tag/array/)


 Given an array `nums`. We define a running sum of an array as `runningSum[i] = sum(nums[0]…nums[i])`.

 Return the running sum of `nums`.

 **Example 1:**

 ```
 Input: nums = [1,2,3,4]
 Output: [1,3,6,10]
 Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
 ```

 **Example 2:**

 ```
 Input: nums = [1,1,1,1,1]
 Output: [1,2,3,4,5]
 Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
 ```

 **Example 3:**

 ```
 Input: nums = [3,1,2,10,1]
 Output: [3,4,6,16,17]
 ```

 **Constraints:**

 *   `1 <= nums.length <= 1000`
 *   `-10^6 <= nums[i] <= 10^6`


 #### Solution

 Language: **Java**

 ```java
 class Solution {
   public static int[] runningSum(int[] nums) {
        int[] rest = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            rest[i] = sum(nums, i);
        }
        return rest;
    }
 ​
    static int sum(int[] nums, int i) {
        int sum = 0;
        for (int m = 0; m <= i; m++) {
            sum = sum + nums[m];
        }
        return sum;
    }
 }
 ```
 */
/**
 * @author: dasouche
 * @date: 2021-03-24 16:27
 **/
public class RunningSumOf1dArray {

    public static void main(String[] args) {
        System.out.println(Arrays.toString(runningSum(new int[]{1,2,3})));
    }

    public static int[] runningSum(int[] nums) {
        int[] rest = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            rest[i] = sum(nums, i);
        }
        return rest;
    }

    static int sum(int[] nums, int i) {
        int sum = 0;
        for (int m = 0; m <= i; m++) {
            sum = sum + nums[m];
        }
        return sum;
    }
}

